package day2;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public
class TestCopy {
    public static
    void main(String[] args) {
        File in=new File("D:\\罗浩\\Pictures\\Camera Roll\\Camera\\VID20220802102704.mp4");
        File out=new File("D:\\io\\movie\\1.mp4");
        if(in.exists()){
            File f3=out.getParentFile();
            if(!f3.exists()) f3.mkdirs();
            //获取开始时间
            long start=System.currentTimeMillis();
            FileInputStream fis= null;
            FileOutputStream fos= null;
            try {
                fis = new FileInputStream(in);
                fos = new FileOutputStream(out);
                byte[] bs=new byte[1024];
                int len=0;
                long size=in.length();
                long i=0;
                while((len=fis.read(bs))!=-1){
                    i+=len;
                    fos.write(bs,0,len);
                    System.out.printf("当前进度：%.5f%%\n",(i*100.0/size));
                }
                //获取结束时间
                long end=System.currentTimeMillis();
                System.out.println("复制完成，耗时："+(end-start)+"ms");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }finally { //关闭流
                try {
                    if(fis!=null) fis.close();
                    if(fos!=null) fos.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }

            }
        }else{
            System.out.println("文件不存在");
        }
    }
}
